package com.lxy.aimin.auth.controller;


import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.lxy.aimin.auth.proxy.ProxyFactory;
import com.lxy.aimin.auth.response.Result;
import com.lxy.aimin.auth.service.UserService;
import com.lxy.aimin.auth.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    RedisTemplate  redisTemplate;

    @Autowired
    UserService userService;

    @GetMapping
    public String dynamicProxies() {
        userService.userById(1);
        return "success";
    }

    @GetMapping("/redis")
    public String redis() {
        redisTemplate.opsForValue().set("name", "lxy");
        return "success";
    }

    @GetMapping("/login")
    public Result<?> login() {
        StpUtil.login(10001);

        SaLoginModel saLoginModel = new SaLoginModel();
        saLoginModel.
        SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
        String tokenName = tokenInfo.getTokenName();
        String tokenValue = tokenInfo.getTokenValue();
        HashMap<String, String> map = new HashMap<>();
        map.put(tokenName, tokenValue);
        return Result.success(map);
    }

    @GetMapping("/logout")
    public String logout() {
        StpUtil.logout();
        return "success";
    }
}
